﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PingPongGame
{
    public class PingPongMain
    {
        
        public const int WorldRows = 25;
        public const int WorldCols = 25;
        //const int RacketLength = 6;

        static void Initialize(Manager manager)
        {
            int startRow = 3;
            int startCol = 2;
            int endCol = WorldCols - 2;
            int endRow = WorldRows - 3;//me
                
            
            for (int i = startCol - 1; i < endCol; i++)
            {

                Block ceilingBlock = new Block(new Position(startRow - 1, i));

                manager.AddObject(ceilingBlock);
            }
            for (int i = startCol +8; i < endCol-8; i++)
            {

                Block tableBlock = new Block(new Position(endRow-4, i));

                manager.AddObject(tableBlock);
            }
            for (int i = startCol - 1; i <= endCol; i++)
            {

                FloorBlock floorBlock = new FloorBlock(new Position(endRow, i));

                manager.AddObject(floorBlock);
            }
            
            for (int i = startRow-1; i < endRow; i++)
            {
                
                LeftBlock currLeftBlock = new LeftBlock(new Position (i,startCol-1));
                RightBlock currRightBlock = new RightBlock(new Position(i, endCol));

                manager.AddObject(currLeftBlock);
                manager.AddObject(currRightBlock);

            }

            Ball theBall = new Ball(new Position(startRow+2, endCol),
                new Position(-1, -1));

            manager.AddObject(theBall);

            UserRacket theRacket = new UserRacket(new Position((WorldRows-startRow)/2+4, startCol));

            manager.AddObject(theRacket);
            
        }

        static void Main(string[] args)
        {
            IDrawer drawer = new ConsoleDrawer(WorldRows, WorldCols);
            IUserInterface keyboard = new KeyboardInterface();

            Manager gameManager = new Manager(drawer, keyboard);

            keyboard.OnUpPressed += (sender, eventInfo) =>
            {
                gameManager.MovePlayerRacketUp();
            };

            keyboard.OnFrontPressed += (sender, eventInfo) =>
            {
                gameManager.MovePlayerRacketFront();
            };
            keyboard.OnBackPressed += (sender, eventInfo) =>
            {
                gameManager.MovePlayerRacketBack();
            };
            keyboard.OnDownPressed += (sender, eventInfo) =>
            {
                gameManager.MovePlayerRacketDown();
            };
            keyboard.OnActionPressed += (sender, eventInfo) =>
            {
                gameManager.ReversePlayerRacket();
            };

            Initialize(gameManager);

            //

            gameManager.Run();
        }
    }
}
